package com.netty.server.sender;


import com.netty.server.base.Connection;
import com.netty.server.base.ConnectionGroup;
import com.netty.server.cmd.ByteResCmd;

/**
 * @author: 王霄
 * @date: 2022/2/3 15:19
 */
public class DefaultCmdSender implements CmdSender {

    private final ConnectionGroup connectionGroup;

    public DefaultCmdSender(ConnectionGroup connectionGroup) {
        this.connectionGroup = connectionGroup;
    }

    @Override
    public void send(CmdRequest request) {
        String mac = request.getMac();
        Connection connection = connectionGroup.get(mac);
        if (connection != null) {
            connection.send(request);
        } else {
            request.getCallback().onTimeout(request);
        }
    }
}
